package com.sl.au.repository;

import java.util.Date;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import com.sl.au.entity.BussinessInspection;

public interface BussinessInspectionRepository extends JpaRepository<BussinessInspection, String> {

	@Query("select b from BussinessInspection b where b.businesssellerBaseInfo.shopName like %?1% "
			+ "or b.businesssellerBaseInfo.shopAdress like %?1% "
			+ "or b.businesssellerBaseInfo.managementRange like %?1% or b.user.name like %?1% or "
			+ "b.businesssellerBaseInfo.id like %?1%")
	Page<BussinessInspection> getInspectName(String key, Pageable pageable);

	@Query("select b from BussinessInspection b where b.businesssellerBaseInfo.id=?1 and b.inspectDate<?2 and b.check is null")
	Page<BussinessInspection> getChecksByTime(String id, Date date, Pageable pageable);
	
	@Query("select b from BussinessInspection b where b.businesssellerBaseInfo.id=?1 and b.inspectDate<?2 and b.check is null and b.needCheck = '1'")
	Page<BussinessInspection> getChecksByTimeAndNeedCheck(String id, Date date, Pageable pageable);

	@Query("select b from BussinessInspection b where b.businesssellerBaseInfo.id=?1 and b.check is not null")
	Page<BussinessInspection> getChecksByHistory(String id, Pageable pageable);

	@Query("select b from BussinessInspection b where b.check.id=?1")
	Page<BussinessInspection> getInspectsByCheckId(String key, Pageable pageable);

}
